
//文档加载事件
document.ready(function (){

    //轮播初始化插件
    let swiper = new Swiper(".mySwiper", {
      autoplay:true,//等同于以下设置
      pagination: { //分页
        el: '.swiper-pagination',
        clickable :true,//可以点击分页
      },
      navigation: {//上一页下一页
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
      loop : true,//循环
    });

     let fileName = '';
     let entName = '';
 
    let apilink = document.querySelectorAll('.api ul li');
    apilink.forEach(function(v){
        v.addEventListener('mouseover',function(){
          v.style.backgroundColor = 'rgb(47,126,233)'//改变背景颜色
          v.style.color = '#fff'//改变字体颜色
          
          let load = v.children[0].src//图片路径
          let firstPos = load.lastIndexOf('/')//最后一个斜杠
          let lastPos = load.lastIndexOf('.')//最后一个点

          fileName = load.substring(firstPos+1,lastPos)//字符串截取
          entName = load.substring(lastPos)//最后一段

          this.children[0].src = `../imgs/${fileName}-c${entName}`
        })
        v.addEventListener('mouseout',function(){
          v.style.color = '#000                                            '//改变字体颜色
          v.style.backgroundColor = '#fff'
          this.children[0].src = `../imgs/${fileName}${entName}`
        })
    })
    
    let box = document.querySelectorAll('.help .box')
    let index = 0;
    setInterval(function(){
      //清除当前的active
      box[index].classList.remove('active')

      ++index;
       //当前的active给谁
      if(index === box.length)index=0;
      
      box[index].classList.add('active')
    },2000)

    //返回顶部
   
    let toTop = document.querySelector('.toTop')
    window.addEventListener('scroll',function(){
      let TOP = document.documentElement.scrollTop
      if(TOP>=1000){
       toTop.style.display = 'block'
      }else{
        toTop.style.display = 'none'
       
      }

    })

     toTop.addEventListener('click',function(){
      //返回顶部
      buffer(document.documentElement,{scrollTop:0})

    })
    
  })